import eel
import os
import sys

wizard_config = {}
def get_default_browser():
    # 尝试找到 Edge 或 Chrome 的可执行文件路径
    edge_path = ''
    chrome_path = ''

    if sys.platform.startswith('win'):
        edge_path = os.path.join(os.environ['ProgramW6432'], 'Microsoft', 'Edge', 'Application', 'msedge.exe')
        chrome_path = os.path.join(os.environ['ProgramW6432'], 'Google', 'Chrome', 'Application', 'chrome.exe')
    elif sys.platform == 'darwin':  # macOS
        edge_path = '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge'
        chrome_path = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
    elif sys.platform == 'linux':  # Linux
        edge_path = '/usr/bin/microsoft-edge'
        chrome_path = '/usr/bin/google-chrome'

    # 检查浏览器是否安装
    if os.path.exists(edge_path):
        return 'edge'
    elif os.path.exists(chrome_path):
        return 'chrome'
    else:
        return 'default'
@eel.expose
def wizard_finished_check():
    if os.path.exists("./work_data/wizard.json"):
        return True
    else:
        return False


@eel.expose
def wizard_part_1(tool):
    global wizard_config
    if not os.path.exists("./work_data"):
        os.mkdir("./work_data")
    wizard_config['tool'] = tool
    
    

browser_mode = get_default_browser()
eel.init('web')
try:
    eel.start('wizard.html',mode='edge')
except:
    try:
        eel.start('wizard.html')
    except:
        eel.start('wizard.html',mode="default")
if browser_mode == 'edge':
    eel.start('index.html', mode='edge')
elif browser_mode == 'chrome':
    eel.start('index.html', mode='chrome')
else:
    eel.start('index.html',mode='default')